%%%%基于16*32基矩阵生成Z=360,180,90,45都不含4,6环的矩阵
clc;
clear all;
close all;

hmx_1d4 = [ 293, 442,  -1,  -1,  37,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
             -1,  -1,  -1,  64,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
             -1,  -1,  -1,   0,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
            346, 133,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
             -1, 218, 384,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1;
             -1,  -1,  -1, 421,   0,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1;
             -1,  74,  96,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1;
             -1, 250,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1;
             -1,  -1,  -1, 272,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1;
             -1,  -1, 373, 384,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1;
            208, 261,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0;
             -1,  -1,  -1, 138,  37,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0;];
Z_Max_1d4 = 512;

hmx_1d3_o1 = [-1,  -1,  -1,  -1, 388,  -1, 218,  73,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1, 260,  -1,  -1,  -1,  -1, 397, 194,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
             470,  -1,  -1,  -1,  -1, 456, 170, 156,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1,  -1,  -1,  83,  -1, 345, 295,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1, 188,  -1,  -1,  -1, 268, 470,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1,  -1, 156,  -1,  -1,  41,  62,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1, 280,  -1,  -1,  -1,  -1,  65, 321,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1, 475,  -1,  -1, 153, 459, 175,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1,  -1,  -1,  -1,  -1, 128, 410, 380,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1,  -1, 283,  -1,  -1, 494, 331,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1;
              -1,  -1, 185,  -1,  -1,  -1, 226, 257,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1;
             509,  -1,  -1,  -1,  -1,  -1, 466,  37,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1;
              -1,  -1,  -1,  -1, 369,  -1, 508, 386,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1;
              -1,  -1,  -1,  48,  -1, 315, 352, 265,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1;
              -1, 392,  -1,  -1,  -1,  -1, 235, 372,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0;
             141,  -1,  -1,  -1,  -1,  -1, 473, 125,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0;];
         
hmx_1d3_o2 = [   -1,  -1,  -1,  -1, 101,  -1, 253,  15,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1, 334,  -1,  -1,  -1,  -1, 171, 369,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            470,  -1,  -1,  -1,  -1, 456, 170, 156,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1,  -1,  -1,  -1, 122,  -1, 220, 318,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1,  -1, 133,  -1,  -1,  -1, 251,  63,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1,  -1,  -1, 418,  -1,  -1, 262,  93,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1, 280,  -1,  -1,  -1,  -1, 386, 352,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1,  -1, 475,  -1,  -1, 153, 459, 175,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
            -1,  -1,  -1,  -1,  -1,  -1, 335, 383, 380,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,
            -1,  -1,  -1, 283,  -1,  -1, 213, 205,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,
            -1,  -1, 185,  -1,  -1,  -1, 255, 421,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,
            270,  -1,  -1,  -1,  -1,  -1, 466,  37,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,
            -1,  -1,  -1,  -1, 369,  -1, 508, 396,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,
            -1,  -1,  -1,  48,  -1, 315, 352, 265,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,
            -1, 392,  -1,  -1,  -1,  -1, 235, 372,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,
            478,  -1,  -1,  -1,  -1,  -1, 473, 291,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0];
        
 hmx_1d3 = [  -1  -1  -1  -1 323  -1 255 257   381   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1 337  -1  -1  -1  -1 179 312  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
             470  -1  -1  -1  -1 486 170 156  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1 370  -1 231 395  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1 211  -1  -1  -1  56 290  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1 139  -1  -1 161 184  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1 221  -1  -1  -1  -1 485  17  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1 475  -1  -1 153 459 175  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1  -1 310 116   0  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
              -1  -1  -1 263  -1  -1 300  67  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
              -1  -1 130  -1  -1  -1 211 319  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
             236  -1  -1  -1  -1  -1 218 139  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1;
              -1  -1  -1  -1 369  -1 307  53  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
              -1  -1  -1  48  -1 315 352 265  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
              -1 392  -1  -1  -1  -1 403 178  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
             509  -1  -1  -1  -1  -1   9 399   381  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0;];
  
Z_Max_1d3 = 512;

hmx_1d2 = [   -1, 501, 389,  -1,  -1,  -1,  -1,  -1, 293, 442,  -1,  -1,  37,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1, 144,  -1,  -1,  -1, 117, 421,  48,  -1,  -1,  -1,  64,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1,  -1, 128, 117, 432,  -1, 176,  -1,  -1,  -1,   0,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
             325,  -1, 250,  -1,  -1,  -1,  -1,  -1, 346, 133,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1, 208,  -1,  -1,  -1, 448,  -1,  -1, 218, 384,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1,  -1;
              -1,  -1,  -1,  -1, 245, 213,  -1, 437,  -1,  -1,  -1, 421,   0,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1,  -1;
              -1,  -1, 506, 282,  -1,  -1,  -1,  -1,  -1,  74,  96,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1,  -1;
              -1,  58, 389,  -1,  -1,  -1,  10,  -1,  -1, 250,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1,  -1;
              64,  -1,  -1,  -1, 442, 128,  -1, 229,  -1,  -1,  -1, 272,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1,  -1;
              -1,  -1,  -1,  -1,  -1, 501,  -1, 314,  -1,  -1, 373, 384,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0,  -1;
              -1,  -1,  37, 346,  -1,  -1,  -1,  -1, 208, 261,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0,   0;
             229,  -1,  -1,  -1,  -1, 352,  -1, 218,  -1,  -1,  -1, 138,  37,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,   0;];
Z_Max_1d2 = 512;

WiMax_ldpc_1d2A=[   -1 94 73 -1 -1 -1 -1 -1 55 83 -1 -1  7  0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1;
                    -1 27 -1 -1 -1 22 79  9 -1 -1 -1 12 -1  0  0 -1 -1 -1 -1 -1 -1 -1 -1 -1;
                    -1 -1 -1 24 22 81 -1 33 -1 -1 -1  0 -1 -1  0  0 -1 -1 -1 -1 -1 -1 -1 -1;
                    61 -1 47 -1 -1 -1 -1 -1 65 25 -1 -1 -1 -1 -1  0  0 -1 -1 -1 -1 -1 -1 -1;
                    -1 -1 39 -1 -1 -1 84 -1 -1 41 72 -1 -1 -1 -1 -1  0  0 -1 -1 -1 -1 -1 -1;
                    -1 -1 -1 -1 46 40 -1 82 -1 -1 -1 79  0 -1 -1 -1 -1  0  0 -1 -1 -1 -1 -1;
                    -1 -1 95 53 -1 -1 -1 -1 -1 14 18 -1 -1 -1 -1 -1 -1 -1  0  0 -1 -1 -1 -1;
                    -1 11 73 -1 -1 -1  2 -1 -1 47 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -1 -1 -1;
                    12 -1 -1 -1 83 24 -1 43 -1 -1 -1 51 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -1 -1;
                    -1 -1 -1 -1 -1 94 -1 59 -1 -1 70 72 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -1;
                    -1 -1  7 65 -1 -1 -1 -1 39 49 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0;
                    43 -1 -1 -1 -1 66 -1 41 -1 -1 -1 26  7 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0;];

WiMax_ldpc_2d3A=[    3  0 -1 -1  2  0 -1  3  7 -1  1  1 -1 -1 -1 -1  1  0 -1 -1 -1 -1 -1 -1;
                    -1 -1  1 -1 36 -1 -1 34 10 -1 -1 18  2 -1  3  0 -1  0  0 -1 -1 -1 -1 -1;
                    -1 -1 12  2 -1 15 -1 40 -1  3 -1 15 -1  2 13 -1 -1 -1  0  0 -1 -1 -1 -1;
                    -1 -1 19 24 -1  3  0 -1  6 -1 17 -1 -1 -1  8 39 -1 -1 -1  0  0 -1 -1 -1;
                    20 -1  6 -1 -1 10 29 -1 -1 28 -1 14 -1 38 -1 -1  0 -1 -1 -1  0  0 -1 -1;
                    -1 -1 10 -1 28 20 -1 -1  8 -1 36 -1  9 -1 21 45 -1 -1 -1 -1 -1  0  0 -1;
                    35 25 -1 37 -1 21 -1 -1  5 -1 -1  0 -1  4 20 -1 -1 -1 -1 -1 -1 -1  0  0;
                    -1  6  6 -1 -1 -1  4 -1 14 30 -1  3 36 -1 14 -1  1 -1 -1 -1 -1 -1 -1  0;];

WiMax_ldpc_2d3B=[    10  -1 101  -1 250  -1 256  -1 192  -1 437  -1 250  -1  80  -1 506   0  -1  -1  -1  -1  -1  -1;
                     -1 368  -1 469  -1 176  -1  16  -1  85  -1 197  -1 213  -1 256  -1   0   0  -1  -1  -1  -1  -1;
                     53  -1 458  -1 330  -1 149  -1 453  -1  85  -1 181  -1 389  -1  -1  -1   0   0  -1  -1  -1  -1;
                     -1 149  -1 170  -1 432  -1 144  -1 469  -1  26  -1 298  -1 197  -1  -1  -1   0   0  -1  -1  -1;
                    122  -1 154  -1  80  -1 160  -1 352  -1 128  -1 266  -1 330  -1  -1  -1  -1  -1   0   0  -1  -1;
                     -1 160  -1 346  -1 288  -1  74  -1   0  -1 160  -1 394  -1   0  -1  -1  -1  -1  -1   0   0  -1;
                    170  -1   0  -1  80  -1 298  -1 453  -1  26  -1  32  -1 277  -1   0  -1  -1  -1  -1  -1   0   0;
                     -1   0  -1 250  -1  69  -1 325  -1 448  -1 293  -1 416  -1 218 506  -1  -1  -1  -1  -1  -1   0;];
hmx_2d3B_n1 = [     242  -1 277  -1  15  -1 205  -1 296  -1  27  -1 303  -1 423  -1 210   0  -1  -1  -1  -1  -1  -1;
                     -1 142  -1  40  -1  28  -1  67  -1 249  -1   1  -1 302  -1 400  -1   0   0  -1  -1  -1  -1  -1;
                    374  -1 100  -1 377  -1 405  -1  12  -1 134  -1 260  -1 440  -1  -1  -1   0   0  -1  -1  -1  -1;
                     -1 405  -1  29  -1 456  -1 306  -1 432  -1 178  -1 445  -1 369  -1  -1  -1   0   0  -1  -1  -1;
                    390  -1  21  -1 216  -1  37  -1  12  -1 456  -1 463  -1 400  -1  -1  -1  -1  -1   0   0  -1  -1;
                     -1 146  -1 187  -1 475  -1  89  -1 351  -1 169  -1  85  -1 245  -1  -1  -1  -1  -1   0   0  -1;
                    160  -1 281  -1 148  -1 275  -1  57  -1 481  -1 349  -1  96  -1 268  -1  -1  -1  -1  -1   0   0;
                     -1 418  -1 236  -1 275  -1 277  -1 178  -1 326  -1 296  -1 307 210  -1  -1  -1  -1  -1  -1   0;];
hmx_2d3B_n2 = [     131  -1 338  -1 207  -1 363  -1 332  -1 276  -1 150  -1 483  -1 506   0  -1  -1  -1  -1  -1  -1;
                     -1 163  -1 167  -1  55  -1 449  -1 297  -1 217  -1 436  -1  41  -1   0   0  -1  -1  -1  -1  -1;
                    430  -1 188  -1 409  -1 173  -1 461  -1 377  -1 327  -1 266  -1  -1  -1   0   0  -1  -1  -1  -1;
                     -1 200  -1 417  -1 275  -1 255  -1 190  -1 364  -1 494  -1 407  -1  -1  -1   0   0  -1  -1  -1;
                    122  -1 154  -1 292  -1 160  -1 352  -1 128  -1 266  -1 330  -1  -1  -1  -1  -1   0   0  -1  -1;
                     -1  24  -1  65  -1  71  -1 228  -1 119  -1 476  -1 128  -1 476  -1  -1  -1  -1  -1   0   0  -1;
                    170  -1   0  -1  80  -1 298  -1 453  -1  26  -1  32  -1 277  -1   0  -1  -1  -1  -1  -1   0   0;
                     -1 421  -1  80  -1 105  -1 324  -1 456  -1  78  -1  35  -1 341 506  -1  -1  -1  -1  -1  -1   0;];
                 
 hmx_2d3 = [ 100  -1  70  -1 223  -1 173  -1 505  -1 210  -1 195  -1 214  -1 506   0  -1  -1  -1  -1  -1  -1;
              -1 217  -1 270  -1  65  -1 294  -1 404  -1 444  -1 369  -1 390  -1   0   0  -1  -1  -1  -1  -1;
              53  -1 333  -1 344  -1 149  -1 300  -1 174  -1 237  -1 423  -1  -1  -1   0   0  -1  -1  -1  -1;
              -1  16  -1 170  -1  17  -1 503  -1 193  -1  26  -1 298  -1 256  -1  -1  -1   0   0  -1  -1  -1;
             122  -1 154  -1 411  -1 160  -1 352  -1 128  -1 266  -1 330  -1  -1  -1  -1  -1   0   0  -1  -1;
              -1 160  -1 346  -1 288  -1  74  -1   0  -1 160  -1 394  -1   0  -1  -1  -1  -1  -1   0   0  -1;
             170  -1   0  -1  80  -1 298  -1 453  -1  26  -1  32  -1 277  -1   0  -1  -1  -1  -1  -1   0   0;
              -1   0  -1 295  -1  69  -1 325  -1 448  -1  53  -1 416  -1 386 506  -1  -1  -1  -1  -1  -1   0;];
          
 hmx_2d3A_180 = [125 267  -1  -1 448 404  -1 177 424  -1 419 176  -1  -1  -1  -1   5   0  -1  -1  -1  -1  -1  -1;
              -1  -1 300  -1 443  -1  -1 476 442  -1  -1 499 271  -1 242  63  -1   0   0  -1  -1  -1  -1  -1;
              -1  -1 250 108  -1 413  -1 213  -1 435  -1 292  -1 258  80  -1  -1  -1   0   0  -1  -1  -1  -1;
              -1  -1 511 487  -1 199 403  -1 409  -1  38  -1  -1  -1 143 132  -1  -1  -1   0   0  -1  -1  -1;
             244  -1  33  -1  -1 159 235  -1  -1 186  -1 133  -1 209  -1  -1   0  -1  -1  -1   0   0  -1  -1;
              -1  -1 406  -1 149  81  -1  -1 505  -1 192  -1 480  -1 381 240  -1  -1  -1  -1  -1   0   0  -1;
             186 282  -1 197  -1 112  -1  -1 102  -1  -1 371  -1  21 222  -1  -1  -1  -1  -1  -1  -1   0   0;
              -1  32 109  -1  -1  -1  21  -1  90 160  -1 317 181  -1  32  -1   5  -1  -1  -1  -1  -1  -1   0];
          
          
hmx_2d3_180 = [  103  -1 301  -1  98  -1 176  -1  56  -1 156  -1 134  -1 495  -1 506   0  -1  -1  -1  -1  -1  -1;
                  -1 322  -1 320  -1 467  -1 331  -1 496  -1 152  -1 365  -1 350  -1   0   0  -1  -1  -1  -1  -1;
                 158  -1   0  -1 125  -1 151  -1 279  -1 140  -1 496  -1  15  -1  -1  -1   0   0  -1  -1  -1  -1;
                  -1  12  -1 266  -1 431  -1 309  -1 294  -1  38  -1 171  -1  59  -1  -1  -1   0   0  -1  -1  -1;
                 122  -1 154  -1 292  -1 160  -1 352  -1 128  -1 266  -1 330  -1  -1  -1  -1  -1   0   0  -1  -1;
                  -1 228  -1 404  -1 499  -1 197  -1 119  -1 476  -1 128  -1 476  -1  -1  -1  -1  -1   0   0  -1;
                 170  -1   0  -1  80  -1 298  -1 453  -1  26  -1  32  -1 277  -1   0  -1  -1  -1  -1  -1   0   0;
                  -1  31  -1 238  -1 317  -1 443  -1  43  -1 113  -1 454  -1 244 506  -1  -1  -1  -1  -1  -1   0;];

  
ZWiMax_ldpc_2d3B = 512;

WiMax_ldpc_3d4B=[     -1, 432,  -1, 149,  -1,  -1,  74, 133,  90,  -1,  -1, 453, 154, 277, 416, 506, 117, 490,   0,   0,  -1,  -1,  -1,  -1;
                     224,  -1,  74, 362, 170,  -1,  -1,  -1,  -1, 373, 229,  58, 192, 213, 176, 304, 202, 128,  -1,   0,   0,  -1,  -1,  -1;
                      -1,  -1, 106,  -1,  -1, 336, 208,  -1, 373, 357,  -1, 202,  21, 384, 250, 154, 320,  26, 426,  -1,   0,   0,  -1,  -1;
                     341,  10,  -1,  -1, 336,  -1,  -1,  16, 272,  -1, 432,  80, 501,  48, 453, 192,  74, 101,  -1,  -1,  -1,   0,   0,  -1;
                      -1, 282, 320, 426,  -1, 138, 400,  -1,  -1,  -1,  -1, 458, 410,   5,  16, 384, 320, 133,  -1,  -1,  -1,  -1,   0,   0;
                     410,  -1,  -1,  -1,  80, 149,  -1, 186,  -1, 384, 160, 362, 453, 448, 138, 341,  58, 474,   0,  -1,  -1,  -1,  -1,   0;];
ZWiMax_ldpc_3d4B = 512;

shorted_3d4B=[    267 417  84  -1  -1 120 350  49 468  49 117 490   0   0  -1  -1  -1  -1;
                  -1  -1  -1  53 427 343 258 204 124 442 396 420  -1   0   0  -1  -1  -1;
                 208  -1 373 357  -1 202  21 384 250 154 320  26 426  -1   0   0  -1  -1;
                  -1 327 272  -1 468 328 406  44 213 192  74 101  -1  -1  -1   0   0  -1;
                 400  -1  -1  -1  -1 425 224 487 125 170 150 456  -1  -1  -1  -1   0   0;
                  -1 186  -1 384 160 362 453 448 138 347  58 324   0  -1  -1  -1  -1   0;];
             
 

WiMax_ldpc_4d5B=[     -1, 432,  -1, 149,  -1,  -1,  74, 133,  90,  -1,  -1, 453, 154, 277, 416, 506, 117, 490,   0,   0,  -1,  -1,  -1,  -1;
                     224,  -1,  74, 362, 170,  -1,  -1,  -1,  -1, 373, 229,  58, 192, 213, 176, 304, 202, 128,  -1,   0,   0,  -1,  -1,  -1;
                      -1,  -1, 106,  -1,  -1, 336, 208,  -1, 373, 357,  -1, 202,  21, 384, 250, 154, 320,  26, 426,  -1,   0,   0,  -1,  -1;
                     341,  10,  -1,  -1, 336,  -1,  -1,  16, 272,  -1, 432,  80, 501,  48, 453, 192,  74, 101,  -1,  -1,  -1,   0,   0,  -1;
                      -1, 282, 320, 426,  -1, 138, 400,  -1,  -1,  -1,  -1, 458, 410,   5,  16, 384, 320, 133,  -1,  -1,  -1,  -1,   0,   0;
                     410,  -1,  -1,  -1,  80, 149,  -1, 186,  -1, 384, 160, 362, 453, 448, 138, 341,  58, 474,   0,  -1,  -1,  -1,  -1,   0;];
ZWiMax_ldpc_4d5B = 96;

shorted_5d6 = [47  4 -1 91 84  8 86 52 82 33  5  0 36 20  4 77 80  0 -1 -1;
                40 47 12 79 47 -1 41 21 12 71 14 72  0 44 49  0  0  0  0 -1;
                67 -1 21 -1 31 24 91 61 81  9 86 78 60 88 67 15 -1 -1  0  0;
                -1 36 13 10 11 20 53 90 29 92 57 30 84 92 11 66 80 -1 -1  0;];

hmx_2d3A11 = [   -1 285  -1 327  -1  78  -1 427  -1 489  -1  -1  -1  53  -1 260 398  -1 309   0  -1  -1  -1  -1  -1  -1  -1;
                309  -1  -1 406 233  -1  -1  -1  -1 439  -1 185 449  -1  -1  -1 254  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
                 -1 493 111  -1  -1 221  88  -1  -1  -1 326  -1  -1  -1  93   7  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
                181  -1  -1  -1 276  -1  -1  27  -1 399  -1 435  -1 120  -1 511  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
                 -1  -1 340  -1  -1  -1 356 119  -1 445  -1  -1 319  -1  75  -1  -1 390 148  -1  -1  -1   0   0  -1  -1  -1;
                 -1 157  -1  46  39  -1  -1  -1  51  -1 230  -1 365  -1  -1  -1 225 493  -1  -1  -1  -1  -1   0   0  -1  -1;
                314  -1 265  -1  -1 241  -1  -1 260  -1 281  -1  -1 339 161  -1  -1 115  -1  -1  -1  -1  -1  -1   0   0  -1;
                 -1 475  -1 307  -1  -1 396  -1 434  -1  -1 131  84  -1  -1  -1 234  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
                 59  -1  -1  -1 337  -1 464 147  -1  -1 178  -1  -1 385  -1 180  -1  -1 309  -1  -1  -1  -1  -1  -1  -1   0;];
             
hmx_2d3A21 = [  110  -1  -1  -1 240  -1 471  64  -1  -1 310  -1  -1  -1 353 314  -1 315 100   0  -1  -1  -1  -1  -1  -1  -1;
                 -1 428  -1 271 171  -1  -1 198  -1 236  -1  -1  -1  20  92  -1  -1 199  -1   0   0  -1  -1  -1  -1  -1  -1;
                242  -1 233  -1  -1 206  -1  -1 181  -1 305  -1  -1 399 500  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
                 -1 279  -1  -1  71  -1 498  -1  -1   9  -1 220 270  -1  -1  43  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
                 -1  -1  90  -1  -1 310  -1  -1  -1 101 354  -1  -1 125  -1  -1 187  -1 434  -1  -1  -1   0   0  -1  -1  -1;
                 81  -1  -1  15  -1  -1 325 286  -1  -1  -1 369 189  -1  -1 106 212  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
                 -1 166 421  -1  -1  -1  87 495  -1  -1 326  -1 297  -1  -1 181  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
                 91  -1  -1 181 306  -1  -1  -1 436  91  -1  -1  -1 465  -1  -1  78  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
                 -1 486  -1 369  -1 328  -1  -1 199  -1  -1 334 349  -1  -1  -1 105 430 100  -1  -1  -1  -1  -1  -1  -1   0;];

hmx_2d3A31 = [    -1 381  -1 205  -1  -1  -1 228  96 233  -1  -1  32  -1 154 359  -1  -1 110   0  -1  -1  -1  -1  -1  -1  -1;
                 158 233  -1  -1  -1  26 442  -1  -1  -1  -1 361  -1 499  -1 440  -1 279  -1   0   0  -1  -1  -1  -1  -1  -1;
                 299  -1 469  30 232  -1  -1  -1  -1  -1  -1  -1 250 294  -1  -1 467  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
                 499 190  -1  -1 398  -1 110 144  -1  -1  95 439  -1  -1  -1 100  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
                  -1  -1  -1 173  34 192  -1 494  -1 140  -1  -1  -1  -1 471  -1  -1  -1 290  -1  -1  -1   0   0  -1  -1  -1;
                  -1  -1 382 486  -1  -1 349  -1  -1  -1 177 473  -1  -1  -1 371  24 345  -1  -1  -1  -1  -1   0   0  -1  -1;
                  -1  -1  -1  -1  -1 183  -1  -1 119  -1 391  -1 507 317 438  -1 476  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
                  -1  -1  -1  -1 144  -1 104   1  50 125 159  -1  -1  -1  -1  -1 418  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
                 295 166 206  -1  -1  -1  -1  -1  -1 263  -1  -1 395 151  -1  -1  -1  87 110  -1  -1  -1  -1  -1  -1  -1   0];

hmx_5d6A11 = [   -1  54 319 313  -1  -1 221 401 213  -1  -1  58  69  -1  -1  41  33  -1 356  -1 164 457 297  -1  71   0  -1  -1  -1  -1;
                506  -1 503 444  -1 404  -1 382  -1 245 499 465  -1 178  -1 294  -1  69  -1  39  -1 100 509  94  -1   0   0  -1  -1  -1;
                 -1  -1  87  -1 159 194  -1  -1 339 394  -1 265  34 236  -1  -1 273 121  -1  14  -1  43  -1 312 318  -1   0   0  -1  -1;
                 60 398  -1  65  -1 373 302  -1  -1 243  -1 361  49  -1 288 184  -1 454  -1  89 368  -1 286 232  -1  -1  -1   0   0  -1;
                 82 379  -1  -1 130  -1 240  36 120  -1 470  -1  -1 445 511 320  -1  -1 219 422  20  -1 247  -1  -1  -1  -1  -1   0   0;
                 -1 288  -1   4 246 115  -1 270  -1 448 496  -1  -1 369 124  -1  84  89  97  -1  -1 396  -1 140  71  -1  -1  -1  -1   0;];

hmx_5d6A21 = [  247  -1  71  29  -1 107  -1 183  -1 234  -1  80 221  -1 259  -1 164 127  -1 470 381  -1 228 295 419   0  -1  -1  -1  -1;
                 83 492  -1  -1 258  -1 321  59 274  -1  -1 274  -1   4  56 228  -1  -1 303  -1 208 146 359  -1  -1   0   0  -1  -1  -1;
                 -1   8  -1 341  -1  96  -1 290 389  -1 387  -1 261  -1  -1 498 219 460 136  -1  -1 337  86 311 268  -1   0   0  -1  -1;
                 -1 485 174  -1  62  82 367  -1  -1 202 511  25  -1 412  -1 415  -1 306  -1 427  -1 474  -1  61  -1  -1  -1   0   0  -1;
                186  -1  -1 501 407  -1   5  -1 185  40  -1 273  -1 212  98  -1 326  -1 313 404  -1 481 323  -1  -1  -1  -1  -1   0   0;
                 -1 179 326 383  -1 437  -1  65  -1 284 272  -1 384 241  -1 406  -1 254  -1 112  14  -1  -1  25 419  -1  -1  -1  -1   0;];  

hmx_2d3B11 = [    -1  -1 338 503  -1 141  -1  -1 140  -1  -1 443  -1  40 109  -1 106  -1 371   0  -1  -1  -1  -1  -1  -1  -1;
                  -1 135  71  -1  -1 378  -1  -1  19 158  -1  -1  51  -1 228  -1  -1 268  -1   0   0  -1  -1  -1  -1  -1  -1;
                 271  -1  -1 160  -1 467  -1 323 241  -1  -1 170  -1  90  -1  -1  -1 164  -1  -1   0   0  -1  -1  -1  -1  -1;
                  -1 309 128  -1  -1  -1 481  -1 436  -1 201  -1  94  -1   7  -1  -1 338  -1  -1  -1   0   0  -1  -1  -1  -1;
                  -1  -1  73  -1  -1 491  -1  -1 299  -1  -1 449  -1 353  20  -1 389  -1 130  -1  -1  -1   0   0  -1  -1  -1;
                 315  -1 458  -1  -1 211  -1  45  -1  -1  30  -1 228  -1  -1 372 215 298  -1  -1  -1  -1  -1   0   0  -1  -1;
                  -1 473  -1 497 503  -1  -1  -1 207 475  -1  76  -1  -1  -1  72  -1 210  -1  -1  -1  -1  -1  -1   0   0  -1;
                 483  -1  -1  -1 469   5 134  -1  -1  -1 328  50  -1  -1 301 323  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
                  -1  -1 373  -1 392  -1  35  37  -1 375  -1 495  -1  -1 408  -1  -1 294 371  -1  -1  -1  -1  -1  -1  -1   0;];
             
hmx_2d3B31 = [    -1  -1 233  -1  -1  -1  -1 251  44  -1  -1 279 184  81 397  -1  -1  99 446   0  -1  -1  -1  -1  -1  -1  -1;
                 288  -1 151  -1  -1 342 289  -1  -1 217  -1 312  76  -1  -1 343  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
                  -1 455 250  46 376  -1  -1  -1 133  -1 294 199  -1  -1 349  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
                  73  -1  -1  -1  -1  -1 288  -1 293  -1 462 301  -1  -1  82 468 440 214  -1  -1  -1   0   0  -1  -1  -1  -1;
                  -1  -1 482  -1  -1 263  -1  -1  -1  -1  -1  -1 212  -1 389  50 271 360  61  -1  -1  -1   0   0  -1  -1  -1;
                  -1  -1 212  -1 232 344  -1  56  -1 161   9 511  -1 193  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
                  -1 489  -1 312  -1 424  -1 436 259 385  -1  -1  -1  -1 223  -1  -1 116  -1  -1  -1  -1  -1  -1   0   0  -1;
                  -1 276 390  -1 498 125  -1  -1 348  -1  -1 484  -1  -1 335  -1  -1  73  -1  -1  -1  -1  -1  -1  -1   0   0;
                 444  -1  -1 361  -1 219 366  -1 239  -1  -1  -1  -1 447  -1  -1 174 400 446  -1  -1  -1  -1  -1  -1  -1   0;];
             
hmx_1d3BM1 = [ -1  -1  -1  -1  -1 348 257  -1 100  97   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1 135  -1  -1  11 476  -1 119  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1 330  -1 234 382 231  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1 389  -1  -1  -1  -1 245 160  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1 259  -1 287 231  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
             389  -1  -1  -1  -1 228 479  32  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1 156  -1  12 299  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1 256  -1 181  32  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1 408  -1  -1 188 429  74  -1 140  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1 137  -1 461  -1 494  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  18  -1  -1 266 480  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
             308 363  -1  -1  -1 502 271  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1 360 404  -1 256  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
              -1 207  75 117  -1  -1  -1  -1 498  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1;
              -1  -1  -1  -1  -1 102 493 341 393  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
              -1  -1  -1  -1  -1 239 295  18 272  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
             367  -1  -1  19 286  -1  -1 267  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
              -1  -1  -1  -1  -1  -1   6 135 444  97  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0;];
          
          
hmx_1d3BM = [ -1  -1  -1  -1  -1  90  -1   8 196 377   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1 491 229  -1 488  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1 121  -1 395 331  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
             304  -1  -1  -1 389  -1 100  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1 338  -1  -1  -1 448  -1 324  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1 130  -1 104  -1 264  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  53  -1  -1 347  -1 463  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1 106  -1 138 496  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1;
              -1 293 226 430  -1  -1  -1  -1  26 370  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1 420  -1 221  -1 268  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1 465 175 501 398  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
              -1  -1  -1  -1  -1  20  -1 127 432  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
              44  -1  -1  -1 110 203  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
             374  -1 477  -1  -1  -1  -1 378  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1;
              -1  -1  -1  -1 347 164  -1  -1 392  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
              -1  -1  -1  -1 141 374  -1  -1 247  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
              -1  -1  -1 188  -1  -1 227 265  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
              -1  -1  -1  -1  -1 476 486 416 511 377  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0];

hmx_1d3_shorted = [   -1 -1 55 83 -1 -1  7  0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1;
                79  9 -1 -1 -1 12 -1  0  0 -1 -1 -1 -1 -1 -1 -1 -1 -1;
                -1 33 -1 -1 -1  0 -1 -1  0  0 -1 -1 -1 -1 -1 -1 -1 -1;
                -1 -1 65 25 -1 -1 -1 -1 -1  0  0 -1 -1 -1 -1 -1 -1 -1;
                84 -1 -1 41 72 -1 -1 -1 -1 -1  0  0 -1 -1 -1 -1 -1 -1;
                -1 82 -1 -1 -1 79  0 -1 -1 -1 -1  0  0 -1 -1 -1 -1 -1;
                -1 -1 -1 14 18 -1 -1 -1 -1 -1 -1 -1  0  0 -1 -1 -1 -1;
                 2 -1 -1 47 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -1 -1 -1;
                -1 43 -1 -1 -1 51 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -1 -1;
                -1 59 -1 -1 70 72 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0 -1;
                -1 -1 39 49 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0  0;
                -1 41 -1 -1 -1 26  7 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1  0];
          
            
hmx_1d3_12X18 = [     -1  -1 293 442  -1  -1  37   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
                     421  48  -1  -1  -1  64  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1;
                      -1 176  -1  -1  -1   0  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1;
                      -1  -1 346 133  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1;
                     448  -1  -1 218 384  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
                      -1 437  -1  -1  -1 421   0  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
                      -1  -1  -1  74  96  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
                      10  -1  -1 250  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1;
                      -1 229  -1  -1  -1 272  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
                      -1 314  -1  -1 373 384  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
                      -1  -1 208 261  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
                      -1 218  -1  -1  -1 138  37  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0];
                  
hmx_2d3_6X18=[ 267 417 441  -1  -1 120 350  49 468  49 117 490   0   0  -1  -1  -1  -1;
              -1  -1  -1 107 427 233 258 204 212 456 244 337  -1   0   0  -1  -1  -1;
             208  -1 373 357  -1 202  21 384 250 154 320  26 426  -1   0   0  -1  -1;
              -1 327 272  -1 468 328 406  44 213 192  74 101  -1  -1  -1   0   0  -1;
             400  -1  -1  -1  -1 425 224 487 125 170 150 456  -1  -1  -1  -1   0   0;
              -1 186  -1 384 160 362 453 448 138 347  58 324   0  -1  -1  -1  -1   0;];    
          
hmx_2d3_6X18=[ -1  71  -1 100  -1  19  -1  81  -1  12  -1  -1  -1 110  -1  65   0  -1  77   0  -1  -1  -1  -1  -1  -1  -1;
   2  -1  -1 123   8  -1  -1  -1  -1  55  -1 122  67  -1  -1  -1  51  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
  -1  44  31  -1  -1  82 126  -1  -1  -1  13  -1  -1  -1  31  74  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
 112  -1  -1  -1 126  -1  -1  54  -1  84  -1  54  -1   1  -1  64  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
  -1  -1  85  -1  -1  -1  89  29  -1 111  -1  -1 100  -1  18  -1  -1  97  37  -1  -1  -1   0   0  -1  -1  -1;
  -1  39  -1  11   9  -1  -1  -1  12  -1  57  -1  91  -1  -1  -1  56 123  -1  -1  -1  -1  -1   0   0  -1  -1;
  78  -1  66  -1  -1  60  -1  -1  65  -1  70  -1  -1  84  40  -1  -1  28  -1  -1  -1  -1  -1  -1   0   0  -1;
  -1  34  -1  72  -1  -1  41  -1  20  -1  -1  32  88  -1  -1  -1  27  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
  55  -1  -1  -1 118  -1  66   9  -1  -1  42  -1  -1  26  -1  95  -1  -1  77  -1  -1  -1  -1  -1  -1  -1   0];

hmx_1d2_gww = [ -1  58  91  -1  -1  -1  -1  -1 100  25  -1  -1   9   0  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1;
  -1  36  -1  -1  -1  39 105   2  -1  -1  -1  82  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1  -1;
  -1  -1  -1  32  37 126  -1 101  -1  -1  -1  56  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1  -1;
  25  -1  24  -1  -1  -1  -1  -1  81  49  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1  -1;
  -1  -1  43  -1  -1  -1  16  -1  -1   7  97  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1  -1;
  -1  -1  -1  -1  72  10  -1  30  -1  -1  -1  22   0  -1  -1  -1  -1   0   0  -1  -1  -1  -1  -1;
  -1  -1 125 114  -1  -1  -1  -1  -1 116 105  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1  -1;
  -1 106  97  -1  -1  -1  53  -1  -1  62  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1  -1;
  16  -1  -1  -1 110  32  -1  57  -1  -1  -1  68  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1  -1;
  -1  -1  -1  -1  -1  85  -1   5  -1  -1  93  34  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0  -1;
  -1  -1   9  85  -1  -1  -1  -1  52  65  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0   0;
  93  -1  -1  -1  -1  91  -1  45  -1  -1  -1 111   9  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1   0];
          
%%
rng('shuffle');

H_c = hmx_1d2_gww;
z_max = 128;
z_max_x = 128;
Z1 = 120;
Z2 = 120;
Z3 = 120;
Z4 = 120;
Z5 = 120;
Z6 = 60;
Z7 = 30;
Z8 = 15;
g4 = 0;
g6 = 0;
g4_pos = zeros(1000, 8);
g6_pos = zeros(3000,12);
[M, N] = size(H_c);
K = N - M;
% H_c = zeros(M,N);                      %%%输出的Zmax=256的矩阵
H_c_b0 = H_c; 
H_c_b1 = -1.*ones(M,N);                  %%Z1
H_c_b2 = -1.*ones(M,N);                  %%Z2
H_c_b3 = -1.*ones(M,N);                  %%Z3
H_c_b4 = -1.*ones(M,N);                  %%Z4
H_c_b5 = -1.*ones(M,N);                  %%Z5
H_c_b6 = -1.*ones(M,N);                  %%Z6
H_c_b7 = -1.*ones(M,N);                  %%Z5
H_c_b8 = -1.*ones(M,N);                  %%Z6
yy = zeros(N,1);                         %%存储变量节点的度
zz = zeros(M,1);                         %%存储校验节点的度

g4s = 1000*ones(1,8);
g6s = 1000*ones(1,8);
set_g4 = [100 100 100 100 0 0 0 0];
set_g6 = [10000 10000 10000 10000 0 0 10 30];
girth_tt = 7;
sum_l = 3;

for ii=2:1:M-1
    if (H_c(ii, K+1)>=0)
        xpos = ii;
        break;
    end
end

for ii=1:1:M
    for jj=1:1:N
        if (H_c(ii,jj)>=0)
            zz(ii)=zz(ii)+1;              %%计算校验节点的度
        end
    end
end
for ii=1:1:N
    for jj=1:1:M
        if (H_c(jj,ii)>=0)
            yy(ii)=yy(ii)+1;              %%计算校验节点的度
        end
    end
end

for ii=1:1:M
    for jj=1:1:N
        if (H_c_b0(ii,jj)>=0)
            H_c_b0(ii,jj) = floor((H_c_b0(ii,jj)*z_max)/z_max_x);
            H_c_b1(ii,jj) = floor((H_c_b0(ii,jj)*Z1)/z_max);
            H_c_b2(ii,jj) = floor((H_c_b0(ii,jj)*Z2)/z_max);
            H_c_b3(ii,jj) = floor((H_c_b0(ii,jj)*Z3)/z_max);
            H_c_b4(ii,jj) = floor((H_c_b0(ii,jj)*Z4)/z_max);
            H_c_b5(ii,jj) = floor((H_c_b0(ii,jj)*Z5)/z_max);
            H_c_b6(ii,jj) = floor((H_c_b0(ii,jj)*Z6)/z_max);
            H_c_b7(ii,jj) = floor((H_c_b0(ii,jj)*Z7)/z_max);
            H_c_b8(ii,jj) = floor((H_c_b0(ii,jj)*Z8)/z_max);
        else
            H_c_b1(ii,jj) = H_c(ii,jj);
            H_c_b2(ii,jj) = H_c(ii,jj);
            H_c_b3(ii,jj) = H_c(ii,jj);
            H_c_b4(ii,jj) = H_c(ii,jj);
            H_c_b5(ii,jj) = H_c(ii,jj);
            H_c_b6(ii,jj) = H_c(ii,jj);
            H_c_b7(ii,jj) = H_c(ii,jj);
            H_c_b8(ii,jj) = H_c(ii,jj);
        end
    end
end

for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b1(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b2(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b3(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b4(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b5(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b6(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b7(ii,jj));
    end
    fprintf('\n');
end
fprintf('\n');
for ii=1:1:M
    for jj=1:1:N
        fprintf('%4d', H_c_b8(ii,jj));
    end
    fprintf('\n');
end

[g4,g6,g4_pos,g6_pos,g4s(1),g6s(1)] = my_girth_4_6(H_c_b1,Z1,z_max,g4,g6,g4_pos,g6_pos, 1);
[g4,g6,g4_pos,g6_pos,g4s(2),g6s(2)] = my_girth_4_6(H_c_b2,Z2,z_max,g4,g6,g4_pos,g6_pos, 0);
[g4,g6,g4_pos,g6_pos,g4s(3),g6s(3)] = my_girth_4_6(H_c_b3,Z3,z_max,g4,g6,g4_pos,g6_pos, 0);
[g4,g6,g4_pos,g6_pos,g4s(4),g6s(4)] = my_girth_4_6(H_c_b4,Z4,z_max,g4,g6,g4_pos,g6_pos, 0);
[g4,g6,g4_pos,g6_pos,g4s(5),g6s(5)] = my_girth_4_6(H_c_b5,Z5,z_max,g4,g6,g4_pos,g6_pos, 0);
[g4,g6,g4_pos,g6_pos,g4s(6),g6s(6)] = my_girth_4_6(H_c_b6,Z6,z_max,g4,g6,g4_pos,g6_pos, 0);
[g4,g6,g4_pos,g6_pos,g4s(7),g6s(7)] = my_girth_4_6(H_c_b7,Z7,z_max,g4,g6,g4_pos,g6_pos, 0);
[g4,g6,g4_pos,g6_pos,g4s(8),g6s(8)] = my_girth_4_6(H_c_b8,Z8,z_max,g4,g6,g4_pos,g6_pos, 0);

 
%% 消4,6环
g4_min = sum(g4s(1:sum_l));
g6_min = sum(g6s(1:sum_l));
cnt_g6 = 0;
cnt_g4 = 0;
g6_flg = 0;

 while (1)
    if (girth_cmp(g4s, set_g4)==1 && girth_cmp(g6s, set_g6)==1)                        %%%无4,6环，输出结果
        for ii=1:1:M
            for jj=1:1:N
               fprintf('%4d',H_c_b0(ii,jj));
            end
            fprintf('\n');
        end
        fprintf('\n');
        break;
    end
    
    
    
    %%消6环
    while(1)
        if (girth_cmp(g4s, set_g4)==0)
            break;                         %%有4环，先消4环
        end
        if (girth_cmp(g6s, set_g6)==1)                         %%无6环，跳出
            break;
        end
        if (girth_cmp(g6s, set_g6)==0)  
            g6_flg = 1;
            
        
                            
            for ii=1:1:g6
               gogo = (mod((H_c_b1(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b1(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b1(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b1(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b1(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b1(g6_pos(ii,11),g6_pos(ii,12))),Z1)==0) || ...
                          (mod((H_c_b2(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b2(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b2(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b2(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b2(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b2(g6_pos(ii,11),g6_pos(ii,12))),Z2)==0) || ...
                          (mod((H_c_b3(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b3(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b3(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b3(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b3(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b3(g6_pos(ii,11),g6_pos(ii,12))),Z3)==0) || ...
                          (mod((H_c_b4(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b4(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b4(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b4(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b4(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b4(g6_pos(ii,11),g6_pos(ii,12))),Z4)==0)  || ...
                          (mod((H_c_b5(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b5(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b5(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b5(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b5(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b5(g6_pos(ii,11),g6_pos(ii,12))),Z5)==0)  || ...
                          (mod((H_c_b6(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b6(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b6(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b6(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b6(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b6(g6_pos(ii,11),g6_pos(ii,12))),Z6)==0)  || ...
                          (mod((H_c_b7(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b7(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b7(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b7(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b7(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b7(g6_pos(ii,11),g6_pos(ii,12))),Z7)==0)  || ...
                          (mod((H_c_b8(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b8(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b8(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b8(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b8(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b8(g6_pos(ii,11),g6_pos(ii,12))),Z8)==0);
               while(gogo)
                      if (zz(g6_pos(ii,1))>zz(g6_pos(ii,5)))
                          if (zz(g6_pos(ii,5))>zz(g6_pos(ii,9)))                %%改变校验节点度小的Z
                              ll = 9;
                              oo = 5;
                          else
                              ll = 5;
                              oo = 9;
                          end
                      else
                          if (zz(g6_pos(ii,1))>zz(g6_pos(ii,9)))
                              ll = 9;
                              oo = 1;
                          else
                              ll = 1;
                              oo = 9;
                          end
                      end
                      while (g6_pos(ii,ll+1)>K)
                           ll = ll + 2;
                           if (ll>12)
                               ll = 1;
                           end
                      end
                      

                      H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1)) = fix(z_max*rand);
                      H_c_b1(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z1/z_max);
                      H_c_b2(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z2/z_max);
                      H_c_b3(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z3/z_max);
                      H_c_b4(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z4/z_max);
                      H_c_b5(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z5/z_max);
                      H_c_b6(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z6/z_max);
                      H_c_b7(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z7/z_max);
                      H_c_b8(g6_pos(ii,ll),g6_pos(ii,ll+1)) = floor(H_c_b0(g6_pos(ii,ll),g6_pos(ii,ll+1))*Z8/z_max);
%                       if (H_c_b(1,17)~=gg)
%                            
%                       end
        
                      if ((mod((H_c_b1(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b1(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b1(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b1(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b1(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b1(g6_pos(ii,11),g6_pos(ii,12))),Z1)==0) || ...
                          (mod((H_c_b2(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b2(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b2(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b2(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b2(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b2(g6_pos(ii,11),g6_pos(ii,12))),Z2)==0) || ...
                          (mod((H_c_b3(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b3(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b3(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b3(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b3(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b3(g6_pos(ii,11),g6_pos(ii,12))),Z3)==0) || ...
                          (mod((H_c_b4(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b4(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b4(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b4(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b4(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b4(g6_pos(ii,11),g6_pos(ii,12))),Z4)==0) || ...
                          (mod((H_c_b5(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b5(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b5(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b5(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b5(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b5(g6_pos(ii,11),g6_pos(ii,12))),Z5)==0) || ...
                          (mod((H_c_b6(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b6(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b6(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b6(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b6(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b6(g6_pos(ii,11),g6_pos(ii,12))),Z6)==0) || ...
                          (mod((H_c_b7(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b7(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b7(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b7(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b7(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b7(g6_pos(ii,11),g6_pos(ii,12))),Z7)==0) || ...
                          (mod((H_c_b8(g6_pos(ii,1),g6_pos(ii,2)) - H_c_b8(g6_pos(ii,3),g6_pos(ii,4)) + H_c_b8(g6_pos(ii,5),g6_pos(ii,6)) -  ...
                               H_c_b8(g6_pos(ii,7),g6_pos(ii,8)) + H_c_b8(g6_pos(ii,9),g6_pos(ii,10)) - H_c_b8(g6_pos(ii,11),g6_pos(ii,12))),Z8)==0));
                          continue;
                      else
                          break;
                      end
               end
            end
         end
         [g4,g6,g4_pos,g6_pos,g4s(1),g6s(1)] = my_girth_4_6(H_c_b1,Z1,z_max,g4,g6,g4_pos,g6_pos, 1);
         [g4,g6,g4_pos,g6_pos,g4s(2),g6s(2)] = my_girth_4_6(H_c_b2,Z2,z_max,g4,g6,g4_pos,g6_pos, 0);
         [g4,g6,g4_pos,g6_pos,g4s(3),g6s(3)] = my_girth_4_6(H_c_b3,Z3,z_max,g4,g6,g4_pos,g6_pos, 0);
         [g4,g6,g4_pos,g6_pos,g4s(4),g6s(4)] = my_girth_4_6(H_c_b4,Z4,z_max,g4,g6,g4_pos,g6_pos, 0);
         [g4,g6,g4_pos,g6_pos,g4s(5),g6s(5)] = my_girth_4_6(H_c_b5,Z5,z_max,g4,g6,g4_pos,g6_pos, 0);
         [g4,g6,g4_pos,g6_pos,g4s(6),g6s(6)] = my_girth_4_6(H_c_b6,Z6,z_max,g4,g6,g4_pos,g6_pos, 0);
         [g4,g6,g4_pos,g6_pos,g4s(7),g6s(7)] = my_girth_4_6(H_c_b7,Z7,z_max,g4,g6,g4_pos,g6_pos, 0);
         [g4,g6,g4_pos,g6_pos,g4s(8),g6s(8)] = my_girth_4_6(H_c_b8,Z8,z_max,g4,g6,g4_pos,g6_pos, 0);
     
         if(girth_cmp(g4s, set_g4)==1 && sum(g6s(1:sum_l))<g6_min)         
          sum(g6s(1:sum_l)) 
          fprintf('\n');
          for ii=1:1:M
              for jj=1:1:N
                  fprintf('%4d', H_c_b0(ii,jj));
              end
              fprintf('\n');
          end
          fprintf('\n');
          g6_min = sum(g6s(1:sum_l));
          H_c_rec = H_c_b0;
         end
         cnt_g6 = cnt_g6 + 1;
    end
   
    %%消4环
    while(1)
        if (girth_cmp(g4s, set_g4)==1)                   %%无4环，跳出
            break;
        end
        if (girth_cmp(g4s, set_g4)==0)                      
%             for ii=1:1:M
%                 for jj=1:1:N
%                     if (H_c_b1(ii,jj)>=0)
%                         zz(ii)=zz(ii)+1;     %%计算校验节点的度     
%                     end
%                 end
%             end                     
            for ii=1:1:g4
               while(1)
                      if (zz(g4_pos(ii,1)) > zz(g4_pos(ii,5)))               %%%%改变校验节点度小的Z
                          ll = 5;
                      else
                          ll = 1;
                      end
                      if(g4_pos(ii,ll+1)>K)
                          ll=ll+2;
                      end
                          
                      H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1)) = fix(z_max*rand);
                      H_c_b1(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z1/z_max);
                      H_c_b2(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z2/z_max);
                      H_c_b3(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z3/z_max);
                      H_c_b4(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z4/z_max);
                      H_c_b5(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z5/z_max);
                      H_c_b6(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z6/z_max);
                      H_c_b7(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z7/z_max);
                      H_c_b8(g4_pos(ii,ll),g4_pos(ii,ll+1)) = floor(H_c_b0(g4_pos(ii,ll),g4_pos(ii,ll+1))*Z8/z_max);
                      
                      if ((mod((H_c_b1(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b1(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b1(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b1(g4_pos(ii,7),g4_pos(ii,8))),Z1)==0) || ...
                          (mod((H_c_b2(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b2(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b2(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b2(g4_pos(ii,7),g4_pos(ii,8))),Z2)==0) || ...
                          (mod((H_c_b3(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b3(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b3(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b3(g4_pos(ii,7),g4_pos(ii,8))),Z3)==0) || ...
                          (mod((H_c_b4(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b4(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b4(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b4(g4_pos(ii,7),g4_pos(ii,8))),Z4)==0) || ...
                          (mod((H_c_b5(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b5(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b5(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b5(g4_pos(ii,7),g4_pos(ii,8))),Z5)==0) || ...
                          (mod((H_c_b6(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b6(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b6(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b6(g4_pos(ii,7),g4_pos(ii,8))),Z6)==0) || ...
                          (mod((H_c_b7(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b7(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b7(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b7(g4_pos(ii,7),g4_pos(ii,8))),Z7)==0) || ...
                          (mod((H_c_b8(g4_pos(ii,1),g4_pos(ii,2)) - H_c_b8(g4_pos(ii,3),g4_pos(ii,4)) + H_c_b8(g4_pos(ii,5),g4_pos(ii,6)) - H_c_b8(g4_pos(ii,7),g4_pos(ii,8))),Z8)==0));
                          continue;
                      else
                          break;
                      end
               end
            end
        end
       [g4,g6,g4_pos,g6_pos,g4s(1),g6s(1)] = my_girth_4_6(H_c_b1,Z1,z_max,g4,g6,g4_pos,g6_pos, 1);
       [g4,g6,g4_pos,g6_pos,g4s(2),g6s(2)] = my_girth_4_6(H_c_b2,Z2,z_max,g4,g6,g4_pos,g6_pos, 0);
       [g4,g6,g4_pos,g6_pos,g4s(3),g6s(3)] = my_girth_4_6(H_c_b3,Z3,z_max,g4,g6,g4_pos,g6_pos, 0);
       [g4,g6,g4_pos,g6_pos,g4s(4),g6s(4)] = my_girth_4_6(H_c_b4,Z4,z_max,g4,g6,g4_pos,g6_pos, 0);
       [g4,g6,g4_pos,g6_pos,g4s(5),g6s(5)] = my_girth_4_6(H_c_b5,Z5,z_max,g4,g6,g4_pos,g6_pos, 0);
       [g4,g6,g4_pos,g6_pos,g4s(6),g6s(6)] = my_girth_4_6(H_c_b6,Z6,z_max,g4,g6,g4_pos,g6_pos, 0);
       [g4,g6,g4_pos,g6_pos,g4s(7),g6s(7)] = my_girth_4_6(H_c_b7,Z7,z_max,g4,g6,g4_pos,g6_pos, 0);
       [g4,g6,g4_pos,g6_pos,g4s(8),g6s(8)] = my_girth_4_6(H_c_b8,Z8,z_max,g4,g6,g4_pos,g6_pos, 0);
       if (g6_flg==0)
           cnt_g4 = cnt_g4 + 1;
       end
       if(girth_cmp(g4s, set_g4)==1 && sum(g6s(1:sum_l))<g6_min)         
          sum(g6s(1:sum_l))  
          fprintf('\n');
          for ii=1:1:M
              for jj=1:1:N
                  fprintf('%4d', H_c_b0(ii,jj));
              end
              fprintf('\n');
          end
          fprintf('\n');
          g6_min = sum(g6s(1:sum_l));
          H_c_rec = H_c_b0;
       end
      
    end
 end


    
        
        

            
            
 
          
        
       
    
    





